<template>
  <vol-box
    :lazy="true"
    v-model="model"
    title="选择安装申请单"
    :height="400"
    :width="1200"
    :padding="5"
    :onModelClose="onModelClose"
  >
    <div>
      <installRequest ref="installRequest"></installRequest>
    </div>
    <template #footer>
      <div>
        <el-button type="primary" size="small" @click="onSelect"
          >确认</el-button
        >
      </div>
    </template>
  </vol-box>
</template>
<script>
import VolBox from "@/components/basic/VolBox.vue";
import installRequest from "@/views/aftersaleinfo/install_request/q_install_request.vue";
//这里使用的vue2语法，也可以写成vue3语法
export default {
  components: {
    "vol-box": VolBox,
    installRequest,
  },
  data() {
    return {
      model: false,
    };
  },
  methods: {
    async onModelClose() {
      this.$refs.installRequest.searchFormFields.Voucher_sub = null;
      this.$refs.installRequest.searchFormFields.Client = null;
      this.$refs.installRequest.searchFormFields.Install_date = [null, null];
      this.$refs.installRequest.searchFormFields.Install_status = null;
      this.$refs.installRequest.searchFormFields.AuditStatus = null;
    },
    open() {
      this.model = true;
      let setIntervalTiem = setInterval(() => {
        if (this.$refs.installRequest) {
          clearInterval(setIntervalTiem);
          this.$refs.installRequest.searchFormFields.AuditStatus = "1";
          this.$refs.installRequest.searchFormFields.Install_status = "5";
          this.$refs.installRequest.searchFormFields.Install_date =[,];
          this.$refs.installRequest.$refs.grid.search();
        }
      });
    },

    onSelect() {
      let rowObj = this.$refs.installRequest.$refs.grid.getSelectRows();
      if (!rowObj.length) {
        this.$message.warning("请选择一条数据");
        return (this.model = true);
      }
      //---------加审批流后开启这个判断--start
      if (rowObj[0].AuditStatus != 1) {
        return this.base.ElMessageFn("该安装申请单未审核通过");
      }
      if (rowObj[0].Install_status != 5) {
        return this.base.ElMessageFn("请选择安装申请完成单据");
      }
      //---------加审批流后开启这个判断--end

      this.$emit("parentCall", ($parent) => {
        $parent.editFormFields.Voucher_sub_install_request =
          rowObj[0].Voucher_sub;
        $parent.editFormFields.Install_requestID = rowObj[0].Install_request;
        $parent.editFormFields.Client = JSON.stringify(rowObj[0].Client);
        $parent.editFormFields.Install_date = rowObj[0].Install_date;
        $parent.editFormFields.Install_address = rowObj[0].Install_address;
        // $parent.editFormFields.Installation_cost = 0;
      });
      this.onModelClose();
      return (this.model = false);
    },
  },
};
</script>